/***************************************************************************
   Filename:    Brush.cpp
   Author:      Josh Partridge
   Description: Extends the plotter class
****************************************************************************/

#include "Brush.h"

/************************************************************************************
 Name:               Brush - default constructor
 Description:        set up window and initialize various attributes of Brush
*************************************************************************************/
Brush::Brush()
{

    hConsoleOutput = GetStdHandle(STD_OUTPUT_HANDLE);
    hConsoleInput = GetStdHandle(STD_INPUT_HANDLE);

    rc.Left = 0;
    rc.Top = 0;
    rc.Right = 119;
    rc.Bottom = 39;

    COORD dwSize = {120, 40};
    SetConsoleScreenBufferSize(hConsoleOutput, dwSize);
    SetConsoleWindowInfo(hConsoleOutput, TRUE, &rc);

    SetConsoleTitle("Breakout");

    // we don't want to be able to see the cursor
    cursor.dwSize = 100;
    cursor.bVisible = FALSE;
    SetConsoleCursorInfo(hConsoleOutput, &cursor);

    coordScreen.X = 0;
    coordScreen.Y = 0;

    SetConsoleTextAttribute(hConsoleOutput, white);
}

/************************************************************************************
 Name:               getPos
 Description:        getter for coordScreen
 Output:
             return: COORD representing coordScreen
*************************************************************************************/
COORD Brush::getPos()
{
    return coordScreen;
}

/************************************************************************************
 Name:               clearCenter
 Description:        clears a specific area of the screen that encompases everything
                     but the border
*************************************************************************************/
void Brush::clearCenter()
{
    for(int i = 0; i<34; i++)
    {
        move(4, 3+i);
        std::cout << "                                                                                                                ";
    }
}

/************************************************************************************
 Name:               clearBox
 Description:        fills an area of the screen with spaces
 Input:
                  x: int representing left side of area
                  y: int representing top side of area
              width: int representing width of area
             height: int representing height of area
*************************************************************************************/
void Brush::clearBox(int x, int y, int width, int height)
{
    for(int yspot=y; yspot<y+height; yspot++)
    {
        for(int xspot=x; xspot<x+width; xspot++)
        {
            plot(xspot, yspot, ' ');
        }
    }
}

/************************************************************************************
 Name:               clearInput
 Description:        flushes the input buffer
*************************************************************************************/
void Brush::clearInput()
{
    FlushConsoleInputBuffer(hConsoleInput);
}
